<?php
/**
 * 评论,留言管理
 * @author cjli
 *
 */
class CommentAction extends AdminAction
{
	public function _initialize()
	{
		parent::_initialize();
	}
	
	//评论列表
	public function index()
	{
		$where = array();
		$language_id = C('language_id') ? C('language_id') : 1;
		$where = array(
			'parent_id'	=> 0,
		);
		if(isset($_POST['search'])){
			if(isset($_POST['email']) && $_POST['email']){
				$where['comment.email'] = trim($_POST['email']);
			}			
			if(isset($_POST['username']) && $_POST['username']){
				$where['comment.username'] = trim($_POST['username']);
			}
			if(isset($_POST['product_id']) && $_POST['product_id']){
				$where['comment.product_id'] = $_POST['product_id'];
			}
			if(isset($_POST['start_time']) && $_POST['start_time']){
				$where['comment.comment_time'] = array('gt',strtotime(trim($_POST['start_time'])));
			}
			if(isset($_POST['end_time']) && $_POST['end_time']){
				$where['comment.comment_time'] = array('lt',strtotime(trim($_POST['end_time'])));
			}
		
		if(isset($_POST['comment_type']) && $_POST['comment_type']){
			$where['comment.comment_type'] = $_POST['comment_type'] ;
		}
		if(isset($_POST['designer_id']) && $_POST['designer_id'] !=-1){
			$where['comment.designer_id'] = intval($_POST['designer_id']) ;
		}
		}
		
		$com_db = D('comment');
		$com_db->where($where);
		$count = $com_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$com_db->limit($Page->firstRow.','.$Page->listRows);
		$com_db->field('user_id,product_id,email,content,comment.id,username,star,comment_time,disabled,comment_type');
		$com_db->where($where);
		$com_db->order('comment_time DESC');
		$commentList = $com_db->select();
		//echo M()->getLastSql();
		foreach ($commentList as $key => $val) {
			$commentList[$key]['product'] = ProductModel::get_product_info($val['product_id'], 1);
		}
		$this->assign('commentList', $commentList);
		
		//设计师列表
		$designerList = UserModel::getUserDesignerList();
		$this->assign('designerList', $designerList);
		$this->assign('commentName', '商品');
		
		$this->display('comment_list');
	}
	
	//查看评论
	public function comment_info()
	{
		$comid = intval($_GET['comid']);
		$com_db = D('comment');
		$com_db->field('comment.*,pri.name as product_name');
		$com_db->join('product_items AS pri ON pri.product_id = comment.product_id');
		$commentInfo = $com_db->where('comment.id='.$comid)->find();
		if(!$commentInfo){
			$this->error('评论不存在！', U('comment/index'), 'comment');
		}
        
	    //查询图片
	    $comment_photo_db = D('comment_photo');
	    $comment_photo = $comment_photo_db->where(array('comid'=>$comid))->order('fid asc')->select();
	    $this->assign('comment_photo', $comment_photo);
		
		if($_POST['dosubmit']){
			
			$data = array(
				'parent_id' => $comid,
				'username' => $_SESSION['admin_user_info']['user_name'],
				'content' => trim($_POST['content']),
				'comment_time' => time(),
			);
			$sub_id = $com_db->add($data);
			$disabled = $_POST['disabled'];
			//修改信息状态
        	$comment_where = array('id' => $comid);
        	$comment = M('comment')->field('is_checked,user_id,product_id,order_id')->where($comment_where)->find();
        	$comment_data = array(
        		'disabled' => $disabled,
        		);
        	//评论第一次审核通过赠送余额 $5
        	if($disabled == 1 && $comment['is_checked'] == 0 && $comment['user_id'] > 0){
        		$money = 5;
        		$comment_photo = M('comment_photo')->where(array('comid'=>$comid))->find();
        		if($comment_photo){
        			$money = 10; //当有上传图片 奖励15 
        		}
				UserModel::user_account_change($comment['user_id'], $money, 0, 1, NULL, 'Product reviewed', NULL);
				UserModel::log_account_change($comment['user_id'], $money, 0, 0 ,0, 'Product reviewed', UserModel::ACT_SAVING);
				$comment_data['is_checked'] = 1;
                //评论返现通知邮件
                $this->ProductReviewEmail($comment);
        	}
            $com_db->where($comment_where)->save($comment_data);

			if($sub_id){
				$this->success('回复成功', U('comment/index'));
			}else{
				$this->error('回复失败', U('comment/index'));
			}
		}else{
			$msgList = $com_db->where('parent_id='.$comid)->order('id DESC')->select();
			$this->assign('msgList', $msgList);
				
			$this->assign('comment', $commentInfo);
			$this->assign('commentName', '商品');
			$this->display('comment_info');
		}
	}
    
    //评论返现通知邮件    
    public function ProductReviewEmail($comment){
    	$orderInfo = OrderModel::getOrderInfo($comment['order_id']);
        $userInfo  = UserModel::getUserInfo($comment['user_id']);
		$email_template = UserModel::getEmailTemplateInfo('ProductReviewEmail', $userInfo['language_id']);
		if($email_template){
			$mailInstance = D(WEB_APP_NAME.'://Email');
			$title   = $email_template['title'];
			$content = $email_template['content'];
			$content = str_replace('{$user_name}', $orderInfo['delivery_first_name'].' '.$orderInfo['delivery_last_name'], $content);
			$where_attr = array('product_id'=>$comment['product_id'],'language_id'=>1);
		    $product_items_info = D('product_items')->where($where_attr)->find();
		    $product_url =  'http://'.$_SERVER['HTTP_HOST'].'/product/'.$comment['product_id'].'-'.generateUrl_un($product_items_info['name']);
			$content = str_replace('{$product_url}', $product_url, $content);
			$mailInstance->sendMail($userInfo['email'], $title, $content);
		}    	
    }
	//查看评论
	public function comment_set()
	{
		$comid = intval($_GET['comid']);
		$com_db = D('comment');
		$comment_photo_db = D('comment_photo');
		if($comid){
			$com_db->field('comment.*,pri.name as product_name');
			$com_db->join('product_items AS pri ON pri.product_id = comment.product_id');
			$commentInfo = $com_db->where('comment.id='.$comid)->find();
			if(!$commentInfo){
				$this->error('评论不存在！', U('comment/index'), 'comment');
			}
            //查询图片
		    $comment_photo = $comment_photo_db->where(array('comid'=>$comid))->order('fid asc')->select();
		    $this->assign('comment_photo', $comment_photo);
		}

		
		
		if($_POST['dosubmit']){
			//保存数据
			$post = $_POST;
			$data = array(
                'product_id' => $post['product_id'],
                'email' => $post['email'],
                'content' => $post['content'],
                'star' => $post['star'],
                'disabled' => $post['disabled'],
				);
            if($comid){
                $com_db->where(array('id'=>$comid))->save($data);
            }else{
			    $data['comment_time'] = time();
			    $comid = $com_db->add($data);
            }

            $comdata = array('comid'=>$comid);
            //绑定图片
    		$photo_name = $post['photo_name'];
			if($photo_name){
				$photo_name = explode(',', $photo_name);
				foreach ($photo_name as $key => $val) {
					if(intval($val)){
                        $comment_photo_db -> where(array('fid'=>$val)) ->save($comdata);
					}
				}
			}   
            //删除图片
    		$del_photo_name = $post['del_photo_name'];
			if($del_photo_name){
				$del_photo_name = explode(',', $del_photo_name);
				foreach ($del_photo_name as $key => $val) {
					if(intval($val)){
                        $comment_photo_db -> where(array('fid'=>$val)) ->delete();
					}
				}
			} 	     
		    $this->success('操作成功', U('comment/index'));
		}else{
			$this->assign('comment', $commentInfo);
			$this->assign('commentName', '商品');
			$this->display('comment_form');
		}
	}
	
	//评论作品列表
	public function designer_comment()
	{
		$where = array();
		$language_id = C('language_id') ? C('language_id') : 1;
		$where = array(
			'pri.language_id' => $language_id,
			'parent_id'	=> 0,
		);
		if(isset($_POST['search'])){
			if(isset($_POST['username']) && $_POST['username']){
				$where['comment.username'] = trim($_POST['username']);
			}
			if(isset($_POST['product_name']) && $_POST['product_name']){
				$where['designer_product.name'] = array('like', '%'.trim($_POST['product_name']).'%');
			}
			if(isset($_POST['start_time']) && $_POST['start_time']){
				$where['comment.comment_time'] = array('gt',strtotime(trim($_POST['start_time'])));
			}
			if(isset($_POST['end_time']) && $_POST['end_time']){
				$where['comment.comment_time'] = array('lt',strtotime(trim($_POST['end_time'])));
			}
		
		if(isset($_POST['comment_type']) && $_POST['comment_type']){
			$where['comment.comment_type'] = $_POST['comment_type'] ;
		}
		if(isset($_POST['designer_id']) && $_POST['designer_id'] !=-1){
			$where['comment.designer_id'] = intval($_POST['designer_id']) ;
		}
		}
		
		$com_db = D('comment');
		$com_db->join('designer_product ON designer_product.id = comment.dproduct_id');
		$com_db->where($where);
		$count = $com_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$com_db->limit($Page->firstRow.','.$Page->listRows);
		$com_db->field('comment.id,comment.username,star,comment_time,disabled,pri.name as product_name,comment_type,dproduct_id');
		$com_db->join('designer_product AS pri ON pri.id = comment.dproduct_id');
		$com_db->where($where);
		$com_db->order('comment_time DESC');
		$commentList = $com_db->select();
		//echo $com_db->getLastSql();
		$this->assign('commentList', $commentList);
		
		//设计师列表
		$designerList = UserModel::getUserDesignerList();
		$this->assign('designerList', $designerList);
		$this->assign('commentName', '作品');
		
		$this->display('comment_list');
	}
	
	//查看评论
	public function comment_designer_info()
	{
		$comid = intval($_GET['comid']);
		$com_db = D('comment');
		$com_db->field('comment.*,pri.name as product_name');
		$com_db->join('designer_product AS pri ON pri.id = comment.dproduct_id');
		$commentInfo = $com_db->where('comment.id='.$comid)->find();
		if(!$commentInfo){
			$this->error('评论不存在！', U('comment/index'), 'comment');
		}
		
		if($_POST['dosubmit']){
			
			$data = array(
				'parent_id' => $comid,
				'username' => $_SESSION['admin_user_info']['user_name'],
				'content' => trim($_POST['content']),
				'comment_time' => time(),
			);
			$sub_id = $com_db->add($data);
//			$com_db->where('id='.$comid)->save(array('disabled' => 2));
			if($sub_id){
				$this->success('回复成功', U('comment/index'));
			}else{
				$this->error('回复失败', U('comment/index'));
			}
		}else{
			$msgList = $com_db->where('parent_id='.$comid)->order('id DESC')->select();
			$this->assign('msgList', $msgList);
				
			$this->assign('comment', $commentInfo);
			$this->assign('commentName', '作品');
			$this->display('comment_info');
		}
	}
	
	//删除评论
	public function comment_delete()
	{
		$comid = intval($_GET['comid']);
		$ids = $_POST['ids'];
		$com_db = D('comment');
		if($comid){
			$com_db->delete($comid);
		}if(!empty($ids)){
			$ids = implode(',', $ids);
			$com_db->delete($ids);
		}
		redirect(U('comment/index'));
	}
	
	//留言管理
	public function guestbook_list()
	{
		$where = array();
		if(isset($_POST['search'])){
			if(isset($_POST['message_type']) && intval($_POST['message_type'])){
				$where['message_type'] = intval($_POST['message_type']);
			}
			if(isset($_POST['username']) && $_POST['username']){
				$where['username'] = trim($_POST['username']);
			}
			if(isset($_POST['title']) && $_POST['title']){
				$where['title'] = array('like', '%'.trim($_POST['title']).'%');
			}
		}
		
		$pageRows = 20;
		if(isset($_REQUEST['pageRows']) && intval($_REQUEST['pageRows'])){
			$pageRows = intval($_REQUEST['pageRows']);
		}
		
		$guestbook_db = D('guestbook');
		$guestbook_db->where($where);
		$count = $guestbook_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count, $pageRows);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$guestbook_db->limit($Page->firstRow.','.$Page->listRows);
		$guestbook_db->where($where);
		$guestbook_db->order('id desc');
		$guestbookList = $guestbook_db->select();
		
		$this->assign('guestbookList', $guestbookList);
		$this->display('guestbook_list');
	}
	
	public function guestbook_edit()
	{
		$gbid = intval($_GET['gbid']);
		$gbdb = D('guestbook');
		$guestbookInfo = $gbdb->find($gbid);
	
		if($_POST['dosubmit']){
			if($_POST['reply']){
				$data = array(
					'reply' => trim($_POST['reply']),
					'reply_time' => time(),
				);
				$gbdb->where('id='.$gbid)->save($data);
				
				$email_template = UserModel::getEmailTemplateInfo('guestBookEmail', $guestbookInfo['language_id']);
				if($email_template && $guestbookInfo['email']){
					$mailInstance = D(WEB_APP_NAME.'://Email');
					$content = str_replace('{$user_name}', $guestbookInfo['username'], $email_template['content']);
					$content = str_replace('{$msg_content}', $guestbookInfo['content'], $content);
					$content = str_replace('{$reply}', trim($_POST['reply']), $content);
					$content = $mailInstance->replaceMail($content);
					$title = str_replace('{$msg_title}', $guestbookInfo['title'], $email_template['title']);
					$mailInstance->sendMail($guestbookInfo['email'], $title, $content);
				}
			}
			
			$this->success('操作成功', U('comment/guestbook_list'));
		}else{
			
			$this->assign('guestbook', $guestbookInfo);
			$this->display('guestbook_edit');
		}
	}
	
	//删除留言
	public function guestbook_delete()
	{
		$ids = $_POST['ids'];
		$guestbook_db = D('guestbook');
		if(!empty($ids)){
			$ids = implode(',', $ids);
			$guestbook_db->delete($ids);
		}
		redirect(U('comment/guestbook_list'));
	}
	
	//评论设置
	public function config()
	{
		$config = SiteModel::getShopConfigList();
		if(isset($_POST['dosubmit'])){
			unset($_POST['dosubmit']);
			SiteModel::updateShopConfig($_POST);
			$this->success('保存成功', U('comment/config'));
		}else{
			$this->assign('config', $config);
		  $this->display('config');
		}
	}
	
	//修改评论状态
	public function change_comment_status_ajax()
	{
		$comid = intval($_GET['comid']);
		$disabled = intval($_GET['disabled']);
		$com_db = D('comment');
		//修改信息状态
    	$comment_where = array('id' => $comid);
    	$comment = M('comment')->field('is_checked,user_id,product_id,order_id')->where($comment_where)->find();
    	$comment_data = array(
    		'disabled' => $disabled,
    		);
    	//评论第一次审核通过赠送余额 $5
    	if($disabled == 1 && $comment['is_checked'] == 0 && $comment['user_id'] > 0){
    		$money = 5;
    		$comment_photo = M('comment_photo')->where(array('comid'=>$comid))->find();
    		if($comment_photo){
    			$money = 10; //当有上传图片 奖励15 
        	}
			UserModel::user_account_change($comment['user_id'], $money, 0, 1, NULL, 'Product reviewed', NULL);
			UserModel::log_account_change($comment['user_id'], $money, 0, 0 ,0, 'Product reviewed', UserModel::ACT_SAVING);
			$comment_data['is_checked'] = 1;
			//评论返现通知邮件
            $this->ProductReviewEmail($comment);
    	}
        $com_db->where($comment_where)->save($comment_data);
	}
	
	//修改评论状态
	public function change_guestbook_status_ajax()
	{
		$gbid = intval($_GET['gbid']);
		$disabled = intval($_GET['disabled']);
		$guestbook_db = D('guestbook');
		$guestbook_db->where('id='.$gbid)->save(array('disabled' => $disabled));
	}
	
	//设计师作品评论
	public function comment_designer_list()
	{
		$where = array();
		if(isset($_POST['search'])){
			if(isset($_POST['username']) && $_POST['username']){
				$where['udc.username'] = trim($_POST['username']);
			}
			if(isset($_POST['product_name']) && $_POST['product_name']){
				$where['udp.designer_name'] = array('like', '%'.trim($_POST['product_name']).'%');
			}
			if(isset($_POST['start_time']) && $_POST['start_time']){
				$where['udc.comment_time'] = array('gt',strtotime(trim($_POST['start_time'])));
			}
			if(isset($_POST['end_time']) && $_POST['end_time']){
				$where['udc.comment_time'] = array('lt',strtotime(trim($_POST['end_time'])));
			}
		if(isset($_POST['comment_type']) && $_POST['comment_type']){
				$where['udc.comment_type'] = $_POST['comment_type'] ;
			}
		}
		$com_db = D('user_designer_comment udc');
		$com_db->join('user_designer_product AS udp ON udp.designer_product_id = udc.designer_product_id');
		$com_db->where($where);
		$count = $com_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$com_db->limit($Page->firstRow.','.$Page->listRows);
		$com_db->field('udc.id,udc.designer_id,udc.username,udc.comment_type,udc.star,udc.comment_time,udc.reply_time,udc.disabled,udp.designer_name as product_name');
		$com_db->join('user_designer_product AS udp ON udp.designer_product_id = udc.designer_product_id');
		$com_db->where($where);
		$com_db->order('udc.comment_time DESC');
		$commentList = $com_db->select();

		//设计师列表
		$designerList = UserModel::getUserDesignerList();
		$this->assign('designerList', $designerList);
		
		$this->assign('commentList', $commentList);
		$this->display('designer_comment_list');
	}
	
	public function comment_designer_eidt()
	{
		$comid = intval($_GET['comid']);
		$com_db = D('user_designer_comment udc');
		$com_db->field('udc.*,users.username AS designer_user_name,udp.designer_name');
		$com_db->join('user_designer_product AS udp ON udp.designer_product_id = udc.designer_product_id');
		$com_db->join('users ON users.id = udc.designer_id');
		$commentInfo = $com_db->where('udc.id='.$comid)->find();
		if(!$commentInfo){
			$this->error('评论不存在！', U('comment/comment_designer_list'));
		}
		if(isset($_POST['dosubmit'])){
			if($_POST['reply_content']){
				$data = array(
					'reply_content' => trim($_POST['reply_content']),
					'reply_time' => time(),
					'disabled' => intval($_POST['disabled']),
				);
				$com_db->where('id='.$comid)->save($data);
			}
			$this->success('回复成功', U('comment/comment_designer_list'));
		}else{
		$this->assign('comment', $commentInfo);
		
			$this->display('designer_comment_edit');
		}
	}
	
	public function comment_designer_delete()
	{
		$comid = intval($_GET['comid']);
		$ids = $_POST['ids'];
		$com_db = D('user_designer_comment');
		if($comid){
			$com_db->delete($comid);
		}if(!empty($ids)){
			$ids = implode(',', $ids);
			$com_db->delete($ids);
		}
		redirect(U('comment/comment_designer_list'));
	}
	
	//晒单设置
	public function shaidan()
	{
		$config = SiteModel::getShopConfigList();
		if(isset($_POST['dosubmit'])){
			unset($_POST['dosubmit']);
			SiteModel::updateShopConfig($_POST);
			$this->success('保存成功', U('comment/shaidan'));
		}else{
			$this->assign('config', $config);
		  $this->display('shaidan');
		}
	}
	
	//删除晒单
	public function shaidan_delete()
	{
		$comid = intval($_GET['comid']);
		$ids = $_POST['ids'];
		$com_db = D('shaidan');
		if($comid){
			
			//关联图片
			$photoList = ProductModel::getShaidanPhotoList($comid);
			if($photoList){
				for($i=0;$i<count($photoList);$i++) {
					//$ass[] = $photoList[$i]['fid'];
					ProductModel::deleteProductPhoto($photoList[$i]['fid']);
				}
			}	
			$shaidan_photo_relation = D('shaidan_photo_relation');
			$shaidan_photo_relation->where('sid='.$comid)->delete();
		
			$com_db->delete($comid);
		}if(!empty($ids)){
			$ids = implode(',', $ids);
			
			//关联图片
			$photoList = ProductModel::getShaidanPhotoList($ids);
			if($photoList){
				for($i=0;$i<count($photoList);$i++) {
					//$ass[] = $photoList[$i]['fid'];
					ProductModel::deleteProductPhoto($photoList[$i]['fid']);
				}
			}
			$shaidan_photo_relation = D('shaidan_photo_relation');
			$shaidan_photo_relation->where('sid='.$ids)->delete();
			$com_db->delete($ids);
		}
		redirect(U('comment/shaidan_list'));
	}
	
	//查看晒单
	public function shaidan_info()
	{
		$comid = intval($_GET['comid']);
		$com_db = D('shaidan');
		$com_db->field('shaidan.*,pri.name as product_name');
		$com_db->join('product_items AS pri ON pri.product_id = shaidan.product_id');
		$shaidanInfo = $com_db->where('shaidan.id='.$comid)->find();
		if(!$shaidanInfo){
			$this->error('评论不存在！', U('comment/shaidan_list'), 'comment');
		}
		
		//关联图片
		//$product_photo_ids = '';
		//$photoList = ProductModel::getProductPhotoList($pid);
		$photoList = ProductModel::getShaidanPhotoList($comid);
		/*if($photoList){
			foreach ($photoList as $file){
				$product_photo_ids .= $file['fid'].',';
			}
		}
		$this->assign('product_photo_ids', $product_photo_ids);*/
		$this->assign('photoList', $photoList);
		
		$this->assign('shaidan', $shaidanInfo);
		$this->display('shaidan_info');
	}
	
	//晒单列表
	public function shaidan_list()
	{	
		$where = array();
		if(isset($_POST['search'])){
			if(isset($_POST['username']) && $_POST['username']){
				$where['shaidan.username'] = trim($_POST['username']);
			}
			if(isset($_POST['product_name']) && $_POST['product_name']){
				$where['product.name'] = array('like', '%'.trim($_POST['product_name']).'%');
			}
			if(isset($_POST['start_time']) && $_POST['start_time']){
				$where['shaidan.comment_time'] = array('gt',strtotime(trim($_POST['start_time'])));
			}
			if(isset($_POST['end_time']) && $_POST['end_time']){
				$where['shaidan.comment_time'] = array('lt',strtotime(trim($_POST['end_time'])));
			}
		}
		$language_id = C('language_id') ? C('language_id') : 1;
		$where = array(
			'pri.language_id' => $language_id,
		);
		$com_db = D('shaidan');
		$com_db->join('product ON product.id = shaidan.product_id');
		$com_db->where($where);
		$count = $com_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$com_db->limit($Page->firstRow.','.$Page->listRows);
		$com_db->field('shaidan.id,username,time,disabled,pri.name as product_name');
		$com_db->join('product_items AS pri ON pri.product_id = shaidan.product_id');
		$com_db->where($where);
		$com_db->order('time DESC');
		$shaidanList = $com_db->select();
		$this->assign('shaidanList', $shaidanList);
		$this->display('shaidan_list');
	}
	
	//修改审核状态
	public function change_shaidan_status_ajax()
	{
		$comid = intval($_GET['comid']);
		$disabled = intval($_GET['disabled']);
		$com_db = D('shaidan');
		$com_db->where('id='.$comid)->save(array('disabled' => $disabled));
		if($disabled > 0){
			$order_shaidan_jifen = C('order_shaidan_jifen');
			if($order_shaidan_jifen){
				$shaidanInfo = $com_db->where('id='.$comid)->find();
				UserModel::logAccountChange($shaidanInfo['user_id'], 0, 0, $order_shaidan_jifen, $order_shaidan_jifen, '晒单获取'.$order_shaidan_jifen.'积分，晒单的产品为：'.$shaidanInfo['title'], UserModel::ACT_SHAIDAN);
			}
		}
	}
	
	//电话咨询列表
	public function order_phone_list()
	{
		$where = array();
		if(isset($_POST['search'])){
			if(isset($_POST['model_id']) && intval($_POST['model_id'])){
				$where['model_id'] = intval($_POST['model_id']);
			}
			if(isset($_POST['order_sn']) && $_POST['order_sn']){
				$where['order_sn'] = array('like', '%'.trim($_POST['order_sn']).'%');
			}
		}
		
		$pageRows = 20;
		if(isset($_REQUEST['pageRows']) && intval($_REQUEST['pageRows'])){
			$pageRows = intval($_REQUEST['pageRows']);
		}
		
		$order_phone_db = D('order_phone');
		$order_phone_db->where($where);
		$count = $order_phone_db->count();//总记录数
		import("ORG.Util.Page");// 导入分页类
		$Page = new Page($count, $pageRows);// 实例化分页类 传入总记录数和每页显示的记录数
		$pageShow = $Page->show();// 分页显示输出
		$this->assign('pageShow', $pageShow);
		//用户列表
		$order_phone_db->limit($Page->firstRow.','.$Page->listRows);
		$order_phone_db->where($where);
		$order_phone_db->order('id DESC');
		$orderphoneList = $order_phone_db->select();
		foreach ($orderphoneList as $key => $value) {
			$orderphoneList[$key]['language'] = D('language')->where(array('id'=>$value['language_id']))->getField('name');
		}
		// echo "<pre />";
		// print_r($orderphoneList);eixt;

		$this->assign('orderphoneList', $orderphoneList);
		$this->display('order_phone_List');
	}
	
	//删除晒单
	public function order_phone_delete()
	{
		$id = intval($_GET['id']);
		$order_phone_db = D('order_phone');
		if($id){
			$order_phone_db->delete($id);
		}
		redirect(U('comment/order_phone_list'));
	}
	
	//查看晒单
	public function order_phone_info()
	{
		$id = intval($_GET['id']);
		$order_phone_db = D('order_phone');
		$orderphoneInfo = $order_phone_db->where('id='.$id)->find();
		if(!$orderphoneInfo){
			$this->error('预约电话不存在！', U('comment/order_phone_list'));
		}
		$orderID = OrderModel::getOrderId($orderphoneInfo['order_sn']);
		if($orderID){
			$orderphoneInfo['product'] = OrderModel::getOrderProductList($orderID); //订单产品列表
			$orderphoneInfo['logs'] = OrderModel::getOrdersLogList($orderID); //订单日志
		}
		
		$this->assign('orderphoneInfo', $orderphoneInfo);
		$this->display('orderphone_info');
	}
	
	//修改电话咨询审核状态
	public function change_order_phone_ajax()
	{
		$comid = intval($_GET['comid']);
		$disabled = intval($_GET['disabled']);
		$com_db = D('order_phone');
		$com_db->where('id='.$comid)->save(array('disabled' => $disabled));
	}
}